from django.db import models
from django.db.models.fields import CharField, BooleanField, TextField,\
    IntegerField
from django.db.models.fields.related import ForeignKey, OneToOneField
#from django.db.models.fields.files import ImageField
from django.contrib.auth.models import User

from django.contrib import admin

# Create your models here.
    
class Author(models.Model):
    user = OneToOneField(User, related_name='author')
    phone = CharField(max_length = 20)
    
class Advertisement(models.Model):
    city = CharField(max_length = 50)
    street = CharField(max_length = 50)
    house_number= IntegerField(blank=True)
    description = TextField()
    show_contact_data = BooleanField()
    author = ForeignKey(Author, related_name='advertisements')

class Offer(models.Model):
    offered_price = IntegerField()
    advertisement = ForeignKey(Advertisement, related_name='offers')
    bidder = ForeignKey(Author, related_name='offers') 

"""
Short thing on photos in our app
1)A way to upload photos from client machine is a django class containing Image or Picture in its name.
However you have to import some external library to make use of it. If you want to know more - ask me and I
will forward your questions to my collegue who has more experience in this stuff.
2)Another thing worth consideration is that if it wouldn't be more convenient to abandon Portfolio class from
models.py in favour of storing all pictures of particular Advertisment somewhere on the file system
in a dictionary named after private key of the add. 
3)I found yet another field - FileField. As the documentation says it handles transport from the browser to server
and in database it represents file as a path
"""
'''
class Portfolio(models.Model):
    #path = FileField()
    pass #to be implemented when adding appropriate functionality
    
or

class Photo(models.Model):
    image = ImageField()
    advertisement = ForeignKey(Advertisement, related_name='photos')
'''
admin.site.register(Author)
admin.site.register(Advertisement)
admin.site.register(Offer)
#admin.site.register(Portfolio)
